<template>
  <div class="rec-courses" id="home-lesson-rec">
    <div class="courses container">
      <img src="~static/images/home/tuijiankecheng-left.png" alt class="bk-left" />
      <p class="tit-head">
        推&nbsp;
        <i>/</i>&nbsp;荐&nbsp;
        <i>/</i>&nbsp;好&nbsp;
        <i>/</i>&nbsp;课
      </p>
      <img src="~static/images/home/tuijiankecheng-right.png" alt class="bk-right" />
      <router-link to="/viewMore" class="more">
        查看更多课程
        <i class="el-icon-arrow-right"></i>
      </router-link>
      <div class="list-courses">
        <div
          class="lesson-item col-xs-3"
          v-for="(item,index) in recList"
          :key="index"
          @click="player(item.lessonId)"
        >
          <div class="lesson-container">
            <div class="home-lesson">
              <div class="lesson-header">
                <img class="lesson-avatar" :src="item.lessonPicPath" />
              </div>
              <div class="lesson-body">
                <div class="lesson-name ui-ellipsis" :title="item.lessonName">{{item.lessonName}}</div>
                <div class="lesson-body-row ui-flex flex-align--center">
                  <div class="lesson-time">{{item.publishTime | date_format("MM月DD日")}}</div>
                  <div class="lesson-price">
                    <span class="lesson-price--vip">vip:{{item.lessonCheapPrice | filterFree}}</span>
                    <span class="lesson-price--normal">{{item.lessonPrice | filterFree}}</span>
                  </div>
                </div>
              </div>
              <div class="lesson-footer ui-flex flex-align--center">
                <div class="head-portrait">
                  <img :src="item.lecturePic" alt width="30" height="30" />
                  <p>{{item.lecturerName}}</p>
                </div>
                <div class="people-number">
                  <i class="el-icon-user-solid"></i>
                  {{item.clickNum}}
                </div>
              </div>
            </div>
          </div>
          <!-- <ul>
            <li></li>
            <li></li>
            <li v-show="item.isVipLesson=='N'">
              <i class="create-time"></i>
              <i class="normal-price">{{item.lessonPrice | filterFree}}</i>
            </li>
            <li v-show="item.isVipLesson=='Y'">
              <i class="create-time">{{item.publishTime | date_format("MM月DD日")}}</i>
              <i class="vip-price"></i>
              <i class="normal-price gray">{{item.lessonPrice | filterFree}}</i>
            </li>
            <li>
              <div class="head-portrait">
                <img :src="item.lecturePic" alt width="30" height="30" />
                <p>{{item.lecturerName}}</p>
              </div>
              <div class="people-number">
                <i class="el-icon-user-solid"></i>
                {{item.clickNum}}
              </div>
            </li>
            <li v-show="item.isNew=='Y'">新课</li>
          </ul>-->
        </div>
      </div>
      <button @click="upDateRes()">
        <i class="el-icon-refresh iconfont" :class="{rotate:showList1}"></i>&nbsp;换一批教程
      </button>
    </div>
  </div>
</template>

<script>
import { getLogonless } from "api/index.js";
export default {
  name: "RecomendLesson",
  props: {
    resetData: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      showList1: true,
      recList: [...this.resetData], //推荐课程
      showList1: false,
      page: {
        // 当前页码
        currentPage: 1,
        // 每页显示的条数
        pageNumber: 10,
        // 总条数
        totalNumber: 0,
        totalPage: 1
      }
    };
  },
  created() {
    this.loadMainlyFlagByPage();
  },
  filters: {
    filterFree(val) {
      return val ? (val == 0 ? "免费" : "￥" + val) : "免费";
    }
  },
  mounted() {},
  methods: {
    // 初始化加载首推课程信息
    loadMainlyFlagByPage() {
      const params = {
        mainlyFlag: "y",
        page: {
          ...this.page
        }
      };
      getLogonless(params, this).then(({ respCode, respMsg, result }) => {
        if (respCode !== "0") {
          return;
        }
        //console.log(res);
        this.recList = result.list;
        this.page.currentPage = result.page.currentPage;
        this.page.totalPage = result.page.totalPage;
      });
    },
    // 换一批首推课程
    upDateRes() {
      this.showList1 = !this.showList1;
      if (this.page.currentPage < this.page.totalPage) {
        this.page.currentPage += 1;
        this.loadMainlyFlagByPage();
      } else {
        this.page.currentPage = 1;
        this.loadMainlyFlagByPage();
      }
    },

    player(lessonId) {
      this.$emit("player", lessonId);
    }
  }
};
</script>

<style scoped lang="scss" >
@import "~/scss/themes/index.scss";

// 推荐课程--最新课程
.rec-courses {
  width: 100%;
  min-width: 1200px;
  .courses {
    width: 1215px;
    margin: 0 auto;
    //height:787px;
    position: relative;

    .bk-left {
      position: absolute;
      left: 431px;
      top: 63px;
    }

    .bk-right {
      position: absolute;
      right: 431px;
      top: 63px;
    }

    .tit-head {
      font-size: 22px;
      font-weight: bold;
      font-stretch: normal;
      color: #4d555d;
      text-align: center;
      padding-top: 60px;
      margin-bottom: 40px;

      i {
        font-size: 12px;
        font-style: normal;
        font-weight: normal;
        color: #8b98a6;
      }
    }

    .more {
      position: absolute;
      right: 7.5px;
      top: 93px;
      font-size: 14px;
      color: #666;

      i {
        color: #666;
      }
    }

    .list-courses {
      height: 545px;
      display: flex;
      //justify-content: space-between;
      //align-content: space-around;
      flex-wrap: wrap;

      .list-margin {
        width: 20%;
        margin-bottom: 33px;
      }

      ul {
        margin: 0 auto;
        width: 225px;
        //height:244px;
        position: relative;
        cursor: pointer;

        li:nth-of-type(1) {
          width: 223px;
          height: 141px;
          //box-sizing: border-box;
          margin: 4px 0 10px 0;
          border-radius: 8px;
          border: 1px solid #dddddd;
          overflow: hidden;

          img {
            width: 100%;
            height: 100%;
          }
        }

        li:nth-of-type(1):hover {
          border: 0;
          margin: 0 0 16px 1px;
          box-shadow: 0 5px 10px 0 #e5e4e4;
        }

        li:nth-of-type(2) {
          font-size: 16px;
          width: 217px;
          //margin-left:4px;
          margin: 0 auto;
          color: #333;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        li:nth-of-type(3),
        li:nth-of-type(4) {
          width: 217px;
          height: 34px;
          line-height: 34px;
          border-bottom: 1px solid #e7e7e7;
          //margin-left:4px;
          margin: 0 auto;
          // display: flex;
          // justify-content: space-between;
          // align-items: center;

          i {
            font-style: normal;
            color: #999;
          }

          i:last-child {
            color: #fc4506;
          }
          s {
            text-align: right;
          }
          .create-time {
            float: left;
          }
          .vip-price {
            float: right;
            color: #fc4506;
          }
          .normal-price {
            float: right;
            color: #fc4506;
            &.gray {
              color: #fc4506;
              margin-right: 1rem;
            }
          }
        }

        li:nth-of-type(5) {
          width: 217px;
          height: 46px;
          //margin-left:4px;
          margin: 0 auto;
          display: flex;
          align-items: center;
          justify-content: space-between;

          .head-portrait {
            height: 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;

            img {
              width: 30px;
              height: 30px;
              border-radius: 50%;
              overflow: hidden;
            }

            p {
              font-size: 14px;
              color: #2b2b2b;
              margin-left: 7px;
              font-weight: normal;
            }
          }

          .people-number {
            color: #9b9b9b;
            font-size: 12px;
          }
        }

        li:nth-of-type(6) {
          width: 40px;
          height: 20px;
          border: 2px solid #f8fafc;
          border-radius: 10px;
          background: #f57743;
          color: #fff8f6;
          text-align: center;
          line-height: 20px;
          font-size: 12px;
          position: absolute;
          top: 12px;
          left: -7px;
        }
      }
    }

    button {
      width: 160px;
      height: 40px;
      background: white;
      border: 1px solid #dddddd;
      border-radius: 5px;
      font-size: 14px;
      color: #666;
      margin: 36px 0 60px 527.5px;
      outline: none;
      cursor: pointer;

      .iconfont {
        display: inline-block;
        transform: rotate(0deg);
        -webkit-transform: rotate(0deg);
        -moz-transform: rotate(0deg);
        -ms-transform: rotate(0deg);
        -o-transform: rotate(0deg);
        transition: transform 2s;
      }

      .rotate {
        display: inline-block;
        transform: rotate(360deg);
        -webkit-transform: rotate(360deg);
        -moz-transform: rotate(360deg);
        -ms-transform: rotate(360deg);
        -o-transform: rotate(360deg);
        transition: transform 2s;
      }
    }

    button:hover {
      background: $brand-primary;
      color: #fff;
      border: 0;
    }
  }
}

.home-lesson {
  display: inline-block;
  width: 225px;

  .lesson-avatar {
    display: inline-block;
    width: 225px;
    height: 141px;
    border-radius: $border-radius-base;
  }

  .lesson-body {
    padding: 10px 0 0 0;
    .lesson-name {
      font-size: 16px;
      color: #333;
    }
    // 时间
    .lesson-time {
      color: #999;
      flex: 0 0 100px;
    }
    .lesson-price {
      flex: 1;
    }
  }
}
</style>
